// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SongDisplayer.java

package presenter;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// Referenced classes of package presenter:
//            SongFile, SongVerse

public class SongDisplayer extends JPanel implements MouseListener, KeyListener {

    public SongDisplayer() {
        this(null);
    }

    public Component getPanel() {
        return scrollPane;
    }

    public SongDisplayer(SongFile sf)
    {
        super(new BorderLayout());
        list=new JList();
        active = 0;
        this.sf = sf;
        update = false;
        out = new JPanel();
        scrollPane = new JScrollPane(out);
        
        //scrollPane.setVisible(true);
        out.setBackground(Color.WHITE);
        add(scrollPane,BorderLayout.CENTER);
        list.addMouseListener(this);
        
        list.addKeyListener(this);
        //addKeyListener(this);
        //setVisible(true);
    }

    public boolean isUpdating()
    {
        return update;
    }

    public SongFile getSong()
    {
        return sf;
    }

    public void setSong(SongFile sf)
    {
        
        this.sf = sf;
        sv = sf.getVerses();
        verses = new JLabel[sv.length];
        //remove(scrollPane);
        //System.out.println(sv.length);
        out = new JPanel(new BorderLayout());
        out.setBackground(Color.WHITE);
        list.setListData(sv);
       
        out.add(list,BorderLayout.CENTER);
        //list.addKeyListener(this);
        list.setCellRenderer(new AlignedListCellRenderer(JLabel.CENTER));
        
        
        //requestFocusInWindow();
        //System.out.println(isFocusOwner());
        length = sv.length;
        
        setActive(0);
        scrollPane.setViewportView(out);
        
        //System.out.println(out.getBounds()+" "+scrollPane.getBounds());
        repaint();
    }

    public int getActive()
    {
        return active;
    }

    public boolean isUpdated()
    {
        if(update)
        {
            update = false;
            return true;
        } else
        {
            return false;
        }
    }
    
    public void setUpdated(boolean updated) {
        this.update=updated;
    }

    public void setActive(int act) {        
        //System.out.println("setting active "+act);
        list.setSelectedValue(sv[act], true);
        
        active = act;
    }

    public void mouseClicked(MouseEvent mouseevent)
    {
    }

    public void mousePressed(MouseEvent me) {
        setActive(list.getSelectedIndex());
        if(me.getClickCount() == 2) {
            update = true;
        }
    }

    public void mouseReleased(MouseEvent mouseevent)
    {
    }

    public void mouseEntered(MouseEvent mouseevent)
    {
    }

    public void mouseExited(MouseEvent mouseevent)
    {
    }

    public void keyTyped(KeyEvent keyevent)
    {
    }

    public void keyPressed(KeyEvent ke)
    {
        int x = ke.getModifiers();
        int key = ke.getKeyCode();
        //System.out.println(list.getSelectedIndex());
        
        //System.out.println("key pressed "+x+" "+key);
        /*int act=list.getSelectedIndex();
        if(x == 0 && key == 38 && active > 0)
            setActive(active - 1);
        if(x == 0 && key == 40 && active < length - 1)
            setActive(active + 1);*/
        if(x==0 && key==10) {
            update=true;
        }    
        setActive(list.getSelectedIndex());
        
    }

    public void keyReleased(KeyEvent keyevent) {
        setActive(list.getSelectedIndex());
    }
    
    public JList getList() {
        return list;
    }
    
    public boolean requestFocusInWindow() {
        boolean test=list.requestFocusInWindow();
        return test;
    }
    
    public boolean isFocusOwner() {
        return list.isFocusOwner();
    }
    
    public void addKeyListener(KeyListener listener) {
        list.addKeyListener(listener);
    }

    SongFile sf;
    SongVerse[] sv;
    JLabel verses[];
    JPanel out;
    JScrollPane scrollPane;
    boolean update;
    int active;
    int length;
    JList list;
}
